package com.moi.summer;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

public class ListViewTitleLayout extends LinearLayout {

    public ListViewTitleLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
        LayoutInflater.from(context).inflate(R.layout.list_view_title, this);
        TextView back = (TextView) findViewById(R.id.tv_back);
        back.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                final Context context = v.getContext();
                AlertDialog.Builder builder = new AlertDialog.Builder(context);
                builder.setTitle("退出")//设置标题
                        .setMessage("是否退出？")//设置提示消息
                        .setPositiveButton("不要", new DialogInterface.OnClickListener() {//设置确定的按键
                            @Override
                            public void onClick(DialogInterface dialog, int which) {

                            }
                        })
                        .setNegativeButton("是的", new DialogInterface.OnClickListener() {//设置取消按键
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                ((Activity) getContext()).finish();
                            }
                        })
                        .setCancelable(false)//设置按返回键是否响应返回，这是是不响应
                        .show();//显示
            }
        });
    }
}
